<?php
	//class for handle link for blog
	//create by mamat, July 14, 2007
	//edited by mamat,
	
	class Link {
		//add link
		function addLink($linkTitleId, $linkName, $linkUrl, $linkDescribtion){
			$mysql = new Mysql();
			$mysql->connect();
			if($mysql->execute("insert into linkdetail (linkId, linkName, linkUrl, linkDescribtion) values($linkTitleId,'$linkName','linkUrl','linkDescribtion')")){
				return true;
			} else {
				return false;
			}
			$mysql->closeConnection();
		}
		
		//add link Title
		function addLinkTitle($linkName, $linkStatus) {
			$mysql = new Mysql();
			$mysql->connect();
			if($mysql->execute("insert into link (linkName, linkStatus) values('$linkName',$linkStatus)")){
				return true;
			} else {
				return false;
			}
			$mysql->closeConnection();
		}
		
		//delete link
		function deleteLink($linkId) {
			$mysql = new Mysql();
			$mysql->connect();
			if($mysql->execute("delete from linkdetail where linkDetailId = $linkId")){
				return true;
			} else {
				return false;
			}
			$mysql->closeConnection();
		}
		
		//delete link Title
		function deleteLinkTitle($linkTitleId) {
			$mysql = new Mysql();
			$mysql->connect();
			if($mysql->execute("delete from link where linkId = $linkTitleId; delete from LinkDetail where linkDetailId = $linkTitleId;")){
				return true;
			} else {
				return false;
			}
			$mysql->closeConnection();
		}
		
		//edit link 
		function editLink($linkId, $linkTitleId, $linkName, $linkUrl, $linkDescribtion) {
			$mysql = new Mysql();
			$mysql->connect();
			if($mysql->execute("update linkdetail set linklinkName = '$linkName', linkUrl = '$linkUrl', linkDescribtion = '$linkDescribtion' where linkDetailId = $linkId")){
				return true;
			} else {
				return false;
			}
			$mysql->closeConnection();
		}
		
		//get link
		function getLinkTitle() {
			$mysql = new Mysql();
			$mysql->connect();
			if($mysql->execute("select * from link order by linkTitle")) {
				return $mysql->getDataSet();				
			} else {
				return false;
			}
				
			$mysql->closeConnection();
		}
		
		function getLink($linkId){
			$mysql = new Mysql();
			$mysql->connect();
			if($mysql->execute("select linkName, linkUrl, linkDescribtion from link,linkdetail where link.linkid = linkdetail.linkid and linkdetail.linkid = $linkId order by linkName")) {
				return $mysql->getDataSet();				
			} else {
				return false;
			}
			$mysql->closeConnection();
		}
	}	
?>